package com.hubox;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController
@Slf4j
@RequestMapping("get")
public class GetController {

    //get 请求使用注解校验，需要在Controller类上添加注解@Validated,否则不能进行校验
    //如校验不通过，需要全局处理ConstraintViolationException异常
    @GetMapping("/req_param")
    public ResponseEntity get(@Length(max = 3, message = "name max length is 3") @RequestParam String name) {
        log.info("accept request: {}", name);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/req_path_param/{name}")
    public ResponseEntity path(@Length(max = 3, message = "name max length is 3") @PathVariable("name") String name) {
        log.info("accept request: {}", name);
        return ResponseEntity.ok().build();
    }
}
